﻿using AutoMapper;
using MediatR;
using S.Organization.API.Application.Command.SheepFarmCommand;
using S.Organization.API.Application.Command.SubcultivationCommand;
using S.Organization.Domian.Model;
using S.Organization.Infrastructure;

namespace S.Organization.API.Application.CommandHandler.SubcultivationCommandHandler
{
    public class DelAllSubcultivationCommandHandler : IRequestHandler<DelAllSubcultivationCommand, int>
    {
        private readonly IBaseRepository<Subcultivation> _repository;
        private readonly IMapper mapper;

        public DelAllSubcultivationCommandHandler(IBaseRepository<Subcultivation> repository, IMapper mapper)
        {
            _repository = repository;
            this.mapper = mapper;
        }

        public async Task<int> Handle(DelAllSubcultivationCommand request, CancellationToken cancellationToken)
        {
            string[] id = request.Ids.ToString().Split(',');

            foreach (var item in id)
            {
                await _repository.DeleteAsync(int.Parse(item));
            }
            return 1;
        }
    }
}
